<?php include('checkLogin.php') ?>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二维码签到</title>
    <link rel="stylesheet" href="bootstrap/bootstrap.css">

</head>
<body style="background: #414057;">
<?php
$course_id = $_POST['id'];
$imageUrl = "#";
$src = "1234567890qwertyuiopasdfghjklzxcvbnm";
$des = "";
for ($i = 0; $i < 10; $i++) {
    $rand = rand(0, 35);
    $c = substr($src, $rand, 1);
    $des = $des . $c;
}
$sql = "delete from qrcode where release_time + valid_time < " . time() . " or course_id='$course_id'";
mysqli_query($cn, $sql);
$sql = "insert into qrcode values ('$des', " . time() . ", 60, '$course_id')";

if (mysqli_query($cn, $sql)) {
    $imageUrl = "http://qr.liantu.com/api.php?text=" . $des;
}

?>
<div class="container" style="text-align: center">
    <img src="<?php echo $imageUrl ?>" class="img-polaroid">
    <br>
    <div style="color: #fff">一分钟后自动刷新</div>
</div>

<script src="bootstrap/jquery-3.2.0.min.js"></script>
<script src="bootstrap/bootstrap.js"></script>
<script>
    setTimeout(refresh, 60000);
    function refresh() {
        post("checkIn.php", {id:'<?php echo $course_id?>'});
    }
    function post(URL, PARAMS) {
        var temp = document.createElement("form");
        temp.action = URL;
        temp.method = "post";
        temp.style.display = "none";
        for (var x in PARAMS) {
            var opt = document.createElement("textarea");
            opt.name = x;
            opt.value = PARAMS[x];
            temp.appendChild(opt);
        }
        document.body.appendChild(temp);
        temp.submit();
        return temp;
    }
</script>

</body>
</html>